home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Games / InputSprocketPPTest / ISpEventPane.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  4.7 KB  |  203 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ISpEventPane.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (BWS)    Brent Schorsch
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <5>     7/17/98    BWS        add header and change creator for SDK
  25. */
  26.  
  27. /*************************************************************************************
  28.  
  29. File:      ISpEventPane.cp
  30.  
  31. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  32.  
  33.  
  34. You may incorporate this sample code into your applications without
  35. restriction, though the sample code has been provided "AS IS" and the
  36. responsibility for its operation is 100% yours.  However, what you are
  37. not permitted to do is to redistribute the source as "DSC Sample Code"
  38. after having made changes. If you're going to re-distribute the source,
  39. we require that you make it clear in the source that the code was
  40. descended from Apple Sample Code, but that you've made changes.
  41.  
  42. *************************************************************************************/
  43.  
  44. #include "ISpEventPane.h"
  45. #include "ISpTestGlobals.h"
  46. #include <CodeFragments.h>
  47. #include <TextUtils.h>
  48. #include <Math64.h>
  49. #include "ISpPPTestTools.h"
  50. #include "LString.h"
  51.  
  52. ISpEventPane::ISpEventPane(LStream *inStream):LOffscreenView(inStream)
  53. {
  54.     mDataValid = false;
  55.     StartIdling();
  56. }
  57.  
  58. ISpEventPane::~ISpEventPane()
  59. {
  60. }
  61.  
  62. ISpEventPane *ISpEventPane::CreateISpEventPaneStream(LStream *inStream)
  63. {
  64.   return (new ISpEventPane(inStream));
  65. }
  66.  
  67.  
  68. void ISpEventPane::SpendTime(const EventRecord &inMacEvent)
  69. {
  70.     inMacEvent;
  71.     
  72.     if (gElementList == nil) { return; }
  73.  
  74.     ISpElementEvent theEvent;
  75.     
  76.     OSStatus theErr;
  77.     Boolean wasEvent;
  78.     
  79.     theErr = ISpElementList_GetNextEvent(    gElementList, 
  80.                                             sizeof(ISpElementEvent),
  81.                                             &theEvent,
  82.                                             &wasEvent);
  83.     
  84.     if (wasEvent)
  85.     {
  86.         mDataValid = true;
  87.         
  88.         mPrintRecord.theError = theErr;        
  89.         mPrintRecord.when = theEvent.when;
  90.         mPrintRecord.data = theEvent.data;
  91.         mPrintRecord.theElement = theEvent.element;
  92.         mPrintRecord.refCon = theEvent.refCon;
  93.         mPrintRecord.percent = theEvent.data;
  94.         float max = 0xffffffff;
  95.         mPrintRecord.percent /= max;
  96.         
  97.         ISpElementInfo info;
  98.         ISpElement_GetInfo(theEvent.element, &info);
  99.         mPrintRecord.label = info.theLabel;
  100.         mPrintRecord.kind = info.theKind;
  101.         BlockMoveData(info.theString, mPrintRecord.theString, 64);
  102.         Refresh();
  103.         UpdatePort();
  104.     }
  105. }
  106.  
  107.  
  108.  
  109. void ISpEventPane::DrawSelf()
  110. {
  111.     if (!mDataValid) { return; }
  112.     
  113.     Rect r;
  114.     Str255 theString;
  115.         
  116.     CalcLocalFrameRect(r);
  117.     r.left += 10;
  118.     EraseRect(&r);
  119.  
  120.     MoveTo(r.left, r.top + 15);
  121.     DrawString("\pError Code:  ");
  122.     NumToString(mPrintRecord.theError, theString);
  123.     DrawString(theString);
  124.  
  125.     MoveTo (r.left, r.top + 30);
  126.     DrawString ("\pTime:  ");
  127.     UnsignedWideToHexString(mPrintRecord.when, theString);
  128.     DrawString (theString);
  129.     
  130.     DrawString ("\p (");
  131.     UnsignedWide microseconds = {0, 0};
  132.     (void) ISpTimeToMicroseconds(&mPrintRecord.when, µseconds);
  133.     
  134. #if TYPE_LONGLONG 
  135.     long double seconds =  ((long double)(* (UInt64 *) µseconds)) / 1000000.0;
  136.     LStr255 secondsStr (seconds, 6, 3);
  137.     DrawString (secondsStr);
  138.     
  139. #else
  140.     if ((Ptr) UInt64ToLongDouble != (Ptr) kUnresolvedCFragSymbolAddress)
  141.     {
  142.         long double seconds =  UInt64ToLongDouble (* (UInt64 *) µseconds) / 1000000;
  143.         LStr255 secondsStr (seconds, 6, 3);
  144.         DrawString (secondsStr);
  145.     }
  146.     else
  147.     {
  148.         SInt32    seconds = 0;
  149.         if (microseconds.hi)
  150.             seconds = (microseconds.hi * (0xFFFFFFFFU/1000000U));
  151.         seconds += (microseconds.lo / 1000000U);
  152.             
  153.         LStr255 secondsStr (seconds);
  154.         DrawString (secondsStr);
  155.     }
  156. #endif
  157.  
  158.     DrawString ("\p seconds)");
  159.  
  160.     MoveTo(r.left, r.top + 45);
  161.     DrawString("\pData:  ");
  162.     UInt32ToHexString(mPrintRecord.data, theString);
  163.     DrawString(theString);
  164.     
  165.     {
  166.         const rectWidth = 100;
  167.         Rect maxRect = {2,0,11,rectWidth};
  168.         Rect progRect = maxRect;
  169.         
  170.         progRect.right = rectWidth * mPrintRecord.percent;
  171.         
  172.         OffsetRect(&maxRect, r.left, r.top + 47);
  173.         OffsetRect(&progRect, r.left, r.top + 47);
  174.         
  175.         ::FrameRect(&maxRect);
  176.         ::PaintRect(&progRect);
  177.     }
  178.  
  179.     MoveTo(r.left, r.top + 75);
  180.     DrawString("\pElement Num:  ");
  181.     UInt32ToHexString((unsigned long) mPrintRecord.theElement, theString);
  182.     DrawString(theString);
  183.  
  184.     MoveTo(r.left, r.top + 90);
  185.     DrawString("\prefCon:  ");
  186.     UInt32ToHexString(mPrintRecord.refCon, theString);
  187.     DrawString(theString);
  188.  
  189.     MoveTo(r.left, r.top + 105);
  190.     DrawString("\pElement Label:  ");
  191.     UInt32ToFourByte(mPrintRecord.label, theString);
  192.     DrawString(theString);
  193.  
  194.     MoveTo(r.left, r.top + 120);
  195.     DrawString("\pElement Kind:  ");
  196.     UInt32ToFourByte(mPrintRecord.kind, theString);
  197.     DrawString(theString);
  198.  
  199.     MoveTo(r.left, r.top + 135);
  200.     DrawString("\pElement Name:  ");
  201.     DrawString(mPrintRecord.theString);
  202.  
  203. }